<template>
  <div>
 <van-list
  v-model='loading'
  :finished='finished'
  finished-text="没有更多了"
  @load='onLoad'
  :offset='50'
  :immediate-check='false'

>
<ArticleItem v-for='(item,index) in list' :key="index+item.houseCode" :obj='item'></ArticleItem>
</van-list>

  </div>
</template>

<script>
import { Toast } from 'vant'

import { SearchAPI } from '@/api'
import ArticleItem from './components/Item.vue'
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false

    }
  },
  props: {
    cityId: String,
    stat: Number,
    end: Number

  },
  components: {
    ArticleItem
  },
  methods: {
    async SearchListAPI () {
      const res = await SearchAPI({
        cityId: this.cityId,
        stat: this.stat,
        end: this.end
      }
      )
      Toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      this.list = res.data.body.list

      if (res.data.body.list.length === 0) { // 加载完成
        this.finished = true
      } else {
        this.stat = this.end++
        this.end += 20

        this.List = [...this.list, ...res.data.body.list]
        this.loading = false// 继续加载滚动
      }
    },

    onLoad () {
      if (this.list.length > 0) {
        this.SearchListAPI()
      }
    }
  },
  created () {
    this.SearchListAPI()
  }
}
</script>

<style>

</style>
